home *** CD-ROM | disk | FTP | other *** search
/ Enter 2007 April / ENTER_CD_04_07.iso / Internet / WinHTTrack 3.23 / httrack-3.23.exe / {app} / src / htslib.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-03-08  |  13.3 KB  |  352 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: Subroutines .h                                         */
  34. /* Author: Xavier Roche                                         */
  35. /* ------------------------------------------------------------ */
  36.  
  37. // Fichier librairie .h
  38.  
  39. #ifndef HTS_DEFH
  40. #define HTS_DEFH 
  41.  
  42. /* dΘfinitions globales */
  43. #include "htsglobal.h"
  44.  
  45. /* basic net definitions */
  46. #include "htsbasenet.h"
  47.  
  48. /* cookies et auth */
  49. #include "htsbauth.h"
  50.  
  51. // Attention, dΘfinition existante Θgalement dans le shell
  52. // (α modifier avec celle-ci)
  53. #define POSTTOK "?>post"
  54.  
  55. #include <stdio.h>
  56.  
  57. #include "htsopt.h"
  58.  
  59. // structure pour paramΦtres supplΘmentaires lors de la requΩte
  60. typedef struct {
  61.   short int user_agent_send;  // user agent (ex: httrack/1.0 [sun])
  62.   short int http11;           // l'en tΩte peut (doit) Ωtre signΘ HTTP/1.1 et non HTTP/1.0
  63.   short int nokeepalive;      // pas de keep-alive
  64.   short int range_used;       // Range utilisΘ
  65.   short int nocompression;    // Pas de compression
  66.   short int flush_garbage;    // recycled
  67.   char user_agent[128];
  68.   char lang_iso[64];
  69.   t_proxy proxy;              // proxy
  70. } htsrequest;
  71.  
  72.  
  73. // structure pour retour d'une connexion/prise d'en tΩte
  74. typedef struct {
  75.   int statuscode;        // status-code, -1=erreur, 200=OK,201=..etc (cf RFC1945)
  76.   short int notmodified; // page ou fichier NON modifiΘ (transfΘrΘ)
  77.   short int is_write;    // sortie sur disque (out) ou en mΘmoire (adr)
  78.   short int is_chunk;    // mode chunk
  79.   short int compressed;  // compressΘ?
  80.   short int empty;       // vide?
  81.   short int keep_alive;  // Keep-Alive?
  82.   short int keep_alive_trailers;  // ..with trailers extension
  83.   int keep_alive_t;      // KA timeout
  84.   int keep_alive_max;    // KA number of requests
  85.   char* adr;             // adresse du bloc de mΘmoire, NULL=vide
  86.   FILE* out;             // Θcriture directe sur disque (si is_write=1)
  87.   LLint size;            // taille fichier
  88.   char msg[80];          // message Θventuel si Θchec ("\0"=non prΘcisΘ)
  89.   char contenttype[64];  // content-type ("text/html" par exemple)
  90.   char contentencoding[64];  // content-encoding ("gzip" par exemple)
  91.   char* location;        // on copie dedans Θventuellement la vΘritable 'location'
  92.   LLint totalsize;       // taille totale α tΘlΘcharger (-1=inconnue)
  93.   short int is_file;     // ce n'est pas une socket mais un descripteur de fichier si 1
  94.   T_SOC soc;             // ID socket
  95.   FILE* fp;              // fichier pour file://
  96. #if HTS_USEOPENSSL
  97.   short int ssl;         // is this connection a SSL one? (https)
  98.   // BIO* ssl_soc;          // SSL structure
  99.   SSL * ssl_con;         // connection structure
  100. #endif
  101.   char lastmodified[64]; // Last-Modified
  102.   char etag[64];         // Etag
  103.   char cdispo[256];      // Content-Disposition coupΘ
  104.   LLint  crange;         // Content-Range
  105.   int debugid;           // debug connection
  106.   /* */
  107.   htsrequest req;  // paramΦtres pour la requΩte
  108.   /*char digest[32+2];  // digest md5 gΘnΘrΘ par le moteur ("" si non gΘnΘrΘ)*/
  109. } htsblk;
  110.  
  111.  
  112. /* ANCIENNE STURCTURE pour cache 1.0 */
  113. typedef struct {
  114.   int statuscode;  // ANCIENNE STURCTURE - status-code, -1=erreur, 200=OK,201=..etc (cf RFC1945)
  115.   int notmodified; // ANCIENNE STURCTURE - page ou fichier NON modifiΘ (transfΘrΘ)
  116.   int is_write;    // ANCIENNE STURCTURE - sortie sur disque (out) ou en mΘmoire (adr)
  117.   char* adr;       // ANCIENNE STURCTURE - adresse du bloc de mΘmoire, NULL=vide
  118.   FILE* out;       // ANCIENNE STURCTURE - Θcriture directe sur disque (si is_write=1)
  119.   int size;        // ANCIENNE STURCTURE - taille fichier
  120.   char msg[80];    // ANCIENNE STURCTURE - message Θventuel si Θchec ("\0"=non prΘcisΘ)
  121.   char contenttype[64];  // ANCIENNE STURCTURE - content-type ("text/html" par exemple)
  122.   char* location;  // ANCIENNE STURCTURE - on copie dedans Θventuellement la vΘritable 'location'
  123.   int totalsize;   // ANCIENNE STURCTURE - taille totale α tΘlΘcharger (-1=inconnue)
  124.   int is_file;     // ANCIENNE STURCTURE - ce n'est pas une socket mais un descripteur de fichier si 1
  125.   T_SOC soc;       // ANCIENNE STURCTURE - ID socket
  126.   FILE* fp;        // ANCIENNE STURCTURE - fichier pour file://
  127.   t_proxy proxy;   // ANCIENNE STURCTURE - proxy
  128.   int user_agent_send;  // ANCIENNE STURCTURE - user agent (ex: httrack/1.0 [sun])
  129.   char user_agent[64];
  130.   int http11;           // ANCIENNE STURCTURE - l'en tΩte doit Ωtre signΘ HTTP/1.1 et non HTTP/1.0
  131. } OLD_htsblk;
  132. /* fin ANCIENNE STURCTURE pour cache 1.0 */
  133.  
  134. // cache pour le dns, pour Θviter de faire des gethostbyname sans arrΩt
  135. typedef struct t_dnscache {
  136.   char iadr[1024];
  137.   struct t_dnscache* n;
  138.   char host_addr[HTS_MAXADDRLEN];    // 4 octets (v4), ou 16 octets (v6)
  139.   int host_length;                   // 4 normalement - ==0  alors en cours de rΘsolution
  140.                                      // ou >16 si sockaddr
  141.                                      //                 ==-1 alors erreur (host n'Θxiste pas)
  142. } t_dnscache;
  143.  
  144.  
  145.  
  146.  
  147. /*
  148. #ifdef __cplusplus
  149. extern "C" {
  150. #endif
  151. */
  152.  
  153. // fonctions unix/winsock
  154. int hts_read(htsblk* r,char* buff,int size);
  155. //int HTS_TOTAL_RECV_CHECK(int var);
  156. LLint check_downloadable_bytes(int rate);
  157.  
  158. HTSEXT_API int hts_init(void);
  159. HTSEXT_API int hts_uninit(void);
  160.  
  161.  
  162. // fonctions principales
  163. int http_fopen(char* adr,char* fil,htsblk* retour);
  164. int http_xfopen(int mode,int treat,int waitconnect,char* xsend,char* adr,char* fil,htsblk* retour);
  165. int http_sendhead(t_cookie* cookie,int mode,char* xsend,char* adr,char* fil,char* referer_adr,char* referer_fil,htsblk* retour);
  166. htsblk httpget(char* url);
  167. //int newhttp(char* iadr,char* err=NULL);
  168. int newhttp(char* iadr,htsblk* retour,int port,int waitconnect);
  169. HTS_INLINE void deletehttp(htsblk* r);
  170. HTS_INLINE void deletesoc(T_SOC soc);
  171. HTS_INLINE void deletesoc_r(htsblk* r);
  172. htsblk http_location(char* adr,char* fil,char* loc);
  173. htsblk http_test(char* adr,char* fil,char* loc);
  174. int check_readinput(htsblk* r);
  175. int check_readinput_t(T_SOC soc, int timeout);
  176. void http_fread(T_SOC soc,htsblk* retour);
  177. LLint http_fread1(htsblk* r);
  178. void treathead(t_cookie* cookie,char* adr,char* fil,htsblk* retour,char* rcvd);
  179. void treatfirstline(htsblk* retour,char* rcvd);
  180. HTSEXT_API void infostatuscode(char* msg,int statuscode);
  181.  
  182. // sous-fonctions
  183. htsblk xhttpget(char* adr,char* fil);
  184. htsblk http_gethead(char* adr,char* fil);
  185. LLint http_xfread1(htsblk* r,int bufl);
  186. HTS_INLINE t_hostent* hts_gethostbyname(char* iadr, void* v_buffer);
  187. HTSEXT_API t_hostent* vxgethostbyname(char* hostname, void* v_buffer);
  188. t_hostent* _hts_ghbn(t_dnscache* cache,char* iadr,t_hostent* retour);
  189. int ftp_available(void);
  190. #if HTS_DNSCACHE
  191. int hts_dnstest(char* _iadr);
  192. t_dnscache* _hts_cache(void);
  193. int _hts_lockdns(int i);
  194. #endif
  195.  
  196. // outils divers
  197. HTS_INLINE TStamp time_local(void);
  198. HTSEXT_API HTS_INLINE TStamp mtime_local(void);
  199. void sec2str(char *s,TStamp t);
  200. HTSEXT_API void qsec2str(char *st,TStamp t);
  201. void time_gmt_rfc822(char* s);
  202. void time_local_rfc822(char* s);
  203. struct tm* convert_time_rfc822(char* s);
  204. int set_filetime(char* file,struct tm* tm_time);
  205. int set_filetime_rfc822(char* file,char* date);
  206. HTS_INLINE void time_rfc822(char* s,struct tm * A);
  207. HTS_INLINE void time_rfc822_local(char* s,struct tm * A);
  208. HTSEXT_API char* int2char(int n);
  209. HTSEXT_API char* int2bytes(LLint n);
  210. HTSEXT_API char* int2bytessec(long int n);
  211. HTSEXT_API char** int2bytes2(LLint n);
  212. HTS_INLINE int sendc(htsblk* r, char* s);
  213. int finput(int fd,char* s,int max);
  214. int binput(char* buff,char* s,int max);
  215. int linput(FILE* fp,char* s,int max);
  216. int linputsoc(T_SOC soc, char* s, int max);
  217. int linputsoc_t(T_SOC soc, char* s, int max, int timeout);
  218. int linput_trim(FILE* fp,char* s,int max);
  219. int linput_cpp(FILE* fp,char* s,int max);
  220. void rawlinput(FILE* fp,char* s,int max);
  221. int strfield(const char* f,const char* s);
  222. #define strfield2(f,s) ( (strlen(f)!=strlen(s)) ? 0 : (strfield(f,s)) )
  223. char* strstrcase(char *s,char *o);
  224. int ident_url_absolute(char* url,char* adr,char* fil);
  225. void fil_simplifie(char* f);
  226. int is_unicode_utf8(unsigned char* buffer, unsigned int size);
  227. void map_characters(unsigned char* buffer, unsigned int size, unsigned int* map);
  228. int ishtml(char* urlfil);
  229. int ishtml_ext(char* a);
  230. int ishttperror(int err);
  231. void guess_httptype(char *s,char *fil);
  232. void get_httptype(char *s,char *fil,int flag);
  233. int get_userhttptype(int setdefs,char *s,char *ext);
  234. void give_mimext(char *s,char *st);
  235. int is_knowntype(char *fil);
  236. int is_userknowntype(char *fil);
  237. int is_dyntype(char *fil);
  238. char* get_ext(char *fil);
  239. int may_unknown(char* st);
  240. HTSEXT_API char* jump_identification(char*);
  241. HTSEXT_API char* jump_toport(char*);
  242. char* strrchr_limit(char* s, char c, char* limit);
  243. HTS_INLINE char* jump_protocol(char* source);
  244. void code64(char* a,char* b);
  245. HTSEXT_API void unescape_amp(char* s);
  246. HTSEXT_API void escape_spc_url(char* s);
  247. HTSEXT_API void escape_in_url(char* s);
  248. HTSEXT_API void escape_uri(char* s);
  249. HTSEXT_API void escape_uri_utf(char* s);
  250. HTSEXT_API void escape_check_url(char* s);
  251. HTSEXT_API char* escape_check_url_addr(char* s);
  252. HTSEXT_API void x_escape_http(char* s,int mode);
  253. HTSEXT_API void escape_remove_control(char* s);
  254. int ehexh(char c);
  255. HTSEXT_API char* unescape_http(char* s);
  256. HTSEXT_API char* unescape_http_unharm(char* s, int no_high);
  257. HTSEXT_API char* antislash_unescaped(char* s);
  258. int ehex(char* s);
  259. char* concat(const char* a,const char* b);
  260. #define copychar(a) concat((a),NULL)
  261. #if HTS_DOSNAME
  262. char* fconcat(char* a,char* b);
  263. char* fconv(char* a);
  264. #else
  265. #define fconv(a) (a)
  266. #define fconcat(a,b) concat(a,b)
  267. #endif
  268. char* fslash(char* a);
  269. char* __fslash(char* a);
  270.  
  271. char* convtolower(char* a);
  272. char* concat(const char* a,const char* b);
  273. void hts_lowcase(char* s);
  274. void hts_replace(char *s,char from,char to);
  275.  
  276. /* Spaces: CR,LF,TAB,FF */
  277. #define  is_space(c)      ( ((c)==' ') || ((c)=='\"') || ((c)==10) || ((c)==13) || ((c)==9) || ((c)==12) || ((c)==11) || ((c)=='\'') )
  278. #define  is_realspace(c)  ( ((c)==' ')                || ((c)==10) || ((c)==13) || ((c)==9) || ((c)==12) || ((c)==11)                )
  279. #define  is_taborspace(c) ( ((c)==' ')                                          || ((c)==9)                             )
  280. #define  is_quote(c)      (               ((c)=='\"')                                                    || ((c)=='\'') )
  281. //HTS_INLINE int is_space(char);
  282. //HTS_INLINE int is_realspace(char);
  283.  
  284. void fprintfio(FILE* fp,char* buff,char* prefix);
  285.  
  286. #if HTS_WIN
  287. #else
  288. int sig_ignore_flag( int setflag );     // flag ignore
  289. #endif
  290.  
  291. void cut_path(char* fullpath,char* path,char* pname);
  292. int fexist(char* s);
  293. /*LLint fsize(char* s);    */
  294. INTsys fpsize(FILE* fp);
  295. INTsys fsize(char* s);    
  296. /* root dir */
  297. HTSEXT_API char* hts_rootdir(char* file);
  298.  
  299. // Threads
  300. #if USE_PTHREAD
  301. typedef void* ( *beginthread_type )( void * );
  302. unsigned long _beginthread( beginthread_type start_address, unsigned stack_size, void *arglist );
  303. #endif
  304.  
  305. /*
  306. #ifdef __cplusplus
  307. }
  308. #endif
  309. */
  310.  
  311.  
  312.  
  313. /* variables globales */
  314. //extern LLint HTS_TOTAL_RECV;  // flux entrant reτu
  315. //extern int HTS_TOTAL_RECV_STATE;  // status: 0 tout va bien 1: ralentir un peu 2: ralentir 3: beaucoup
  316. extern HTSEXT_API hts_stat_struct HTS_STAT;
  317. extern int _DEBUG_HEAD;
  318. extern FILE* ioinfo;
  319.  
  320. /* constantes */
  321. extern const char hts_mime_keep[][32];
  322. extern const char hts_mime[][2][32];
  323. extern const char hts_detect[][32];
  324. extern const char hts_detectbeg[][32];
  325. extern const char hts_nodetect[][32];
  326. extern const char hts_detectURL[][32];
  327. extern const char hts_detectandleave[][32];
  328. extern const char hts_detect_js[][32];
  329.  
  330. // defaut wrappers
  331. void  __cdecl htsdefault_init(void);
  332. void  __cdecl htsdefault_uninit(void);
  333. int   __cdecl htsdefault_start(void* opt);
  334. int   __cdecl htsdefault_chopt(void* opt);
  335. int   __cdecl htsdefault_end(void);
  336. int   __cdecl htsdefault_checkhtml(char* html,int len,char* url_adresse,char* url_fichier);
  337. int   __cdecl htsdefault_loop(void* back,int back_max,int back_index,int lien_n,int lien_tot,int stat_time,hts_stat_struct* stats);
  338. char* __cdecl htsdefault_query(char* question);
  339. char* __cdecl htsdefault_query2(char* question);
  340. char* __cdecl htsdefault_query3(char* question);
  341. int   __cdecl htsdefault_check(char* adr,char* fil,int status);
  342. void  __cdecl htsdefault_pause(char* lockfile);
  343. void  __cdecl htsdefault_filesave(char*);
  344. int   __cdecl htsdefault_linkdetected(char* link);
  345. int   __cdecl htsdefault_xfrstatus(void* back);
  346. int   __cdecl htsdefault_savename(char* adr_complete,char* fil_complete,char* referer_adr,char* referer_fil,char* save);
  347. // end defaut wrappers
  348.  
  349. #endif
  350.  
  351.  
  352.